﻿using System;
using System.Collections.Generic;
using System.Text;
using FunctionalCLR.Core;

namespace FunctionalCLR.Core.Function.List {
    public class ListIntersectionNode : FuncNode {

        public ListIntersectionNode()
            : base() {
            this.Value = "intersection";
        }

        public override FuncNode GetReversedFunction(int index) {
            throw new NotImplementedException();
        }

        public override object Evaluate() {
            bool found = false;
            ListNode result = new ListNode();

            for (int i = 0; i < Children.Count; i++) {
                ListNode c = (ListNode)Children[i];
                foreach (Node u in c.Children) {
                    for (int j = i + 1; j < Children.Count; j++) {
                        ListNode d = (ListNode)Children[j];
                        foreach (Node v in d.Children) {
                            if (u.Value == v.Value) {
                                found = true;
                            }
                        }
                    }
                }
            }

            return result;
        }
    }
}
